#include "defaultstateproperty.h"

defaultstateproperty::defaultstateproperty(node *myblock1, bool fa)
{
    this->cdf_failure_active = fa;
    this->myblock1 = myblock1;
    setupUi(this);

    this->groupBox_erlang_5->hide();
    this->groupBox_uniforme_5->hide();
    this->groupBox_weibull_5->hide();

    connect(pushButton_11, SIGNAL(clicked()), this, SLOT(cdf_failure_active_accept()));
    connect(pushButton_11, SIGNAL(clicked()), this, SLOT(accept()));
    connect(pushButton_12, SIGNAL(clicked()), this, SLOT(reject()));
    connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboBox_currentIndexChanged(int)));
}


void defaultstateproperty::cdf_failure_active_accept()
{
    if(this->cdf_failure_active == true)//si devono salvare i dati della cdf per lo stato failure
    {
        this->myblock1->getBlock()->getFailureDep()->setCdf(this->comboBox->currentText(), this);
    }
    else//si devono salvare i dat della cdf per lo stato active
    {
        this->myblock1->getBlock()->getActiveDep()->setCdf(this->comboBox->currentText(), this);
    }
}

void defaultstateproperty::comboBox_currentIndexChanged(int currentIndex)
{
    QString cdfSelected = this->comboBox->itemText(currentIndex);

    if(cdfSelected == "Weibull")
    {
        this->groupBox_erlang_5->hide();
        this->groupBox_uniforme_5->hide();

        this->groupBox_weibull_5->setVisible(true);
    }
    else if(cdfSelected == "Erlang")
    {
        this->groupBox_weibull_5->hide();
        this->groupBox_uniforme_5->hide();
        this->groupBox_erlang_5->setVisible(true);
    }
    else if(cdfSelected == "Uniforme")
    {
        this->groupBox_erlang_5->hide();
        this->groupBox_weibull_5->hide();
        this->groupBox_uniforme_5->setVisible(true);
    }
    else if(cdfSelected == "Not repairable")
    {
        this->groupBox_erlang_5->hide();
        this->groupBox_uniforme_5->hide();
        this->groupBox_weibull_5->hide();
    }

}

void defaultstateproperty::setGroupBoxCdf(cdf *distribution)
{
    if(distribution->getType() == "Weibull")
    {
        cdfWeibull *d = (cdfWeibull *)distribution;
        this->lineEdit_kappa_5->setText(d->getKappa());
        this->lineEdit_lambda_5->setText(d->getLambda());
        this->comboBox->setCurrentIndex(this->comboBox->findText("Weibull", Qt::MatchExactly));
        this->groupBox_weibull_5->show();
    }
    else if(distribution->getType() == "Erlang")
    {
        cdfErlang *d = (cdfErlang *)distribution;
        this->lineEdit_alfa_6->setText(d->getAlfa());
        this->lineEdit_erre_6->setText(d->getErre());
        this->comboBox->setCurrentIndex(this->comboBox->findText("Erlang", Qt::MatchExactly));
        this->groupBox_erlang_5->show();
    }
    else if(distribution->getType() == "Uniforme")
    {
        cdfUniforme *d = (cdfUniforme *)distribution;
        this->lineEdit_a_5->setText(d->getA());
        this->lineEdit_b_5->setText(d->getB());
        this->comboBox->setCurrentIndex(this->comboBox->findText("Uniforme", Qt::MatchExactly));
        this->groupBox_uniforme_5->show();
    }
    else if(distribution->getType() == "Not repairable")
    {
        cdf *d = distribution;
        this->comboBox->setCurrentIndex(this->comboBox->findText("Not repairable", Qt::MatchExactly));
        this->groupBox_erlang_5->hide();
        this->groupBox_uniforme_5->hide();
        this->groupBox_weibull_5->hide();

    }

}
